package com.uenpay.im.invokeitems;

import com.uenpay.im.ui.old.activity.group.GroupType;
import com.uenpay.im.configuration.APIConfiguration;
import com.uenpay.im.entities.HttpInvokeResult;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.HashMap;


/**
 * @author SL
 * @copyRight http://www.qiyunxin.com
 */
public class GroupAddPersonInvokeItem extends BaseHttpInvokeItem {
	public class GroupAddPersonInvokeItemResult extends HttpInvokeResult {
		public int status;
		public String msg;
	}

	public GroupAddPersonInvokeItemResult getOutPut() {
		return (GroupAddPersonInvokeItemResult) GetResultObject();
	}

	public GroupAddPersonInvokeItem(int group_type,String chat_id, String custids) {
		String url = "";
		if(group_type == GroupType.NORMAL_GROUP){
			url = APIConfiguration.getBaseUrl() + "Chat/Chat/addChatCusts?"
					+ APIConfiguration.getCustIdAndToken();
		}else{
			url = APIConfiguration.getBaseUrl() + "Chat/SpecialChat/inviteChatCusts?"
					+ APIConfiguration.getCustIdAndToken();
		}
		HashMap<String, String> mRequestParams = new HashMap<String, String>();
		mRequestParams.put("chatid", chat_id);
		mRequestParams.put("custids", custids);
		SetRequestParams(mRequestParams);
		SetUrl(url);
	}

	@Override
	protected Object DeserializeResult(String responseBody) {
		GroupAddPersonInvokeItemResult result = new GroupAddPersonInvokeItemResult();
		try {
			JSONObject json = new JSONObject(responseBody);
			result.status = json.optInt("status");
			result.msg = json.optString("msg");
		} catch (JSONException e) {
			e.printStackTrace();
			return result;
		}

		return result;
	}

}
